/**
 * Created by admin on 2017/7/12.
 */
(function () {
    var module = {};
    var tools = Tools();
    var isIdentification;
    var redPage,totalMoney;
    var redList,moneyList=[];

    module.init=function () {
        tools.getUserInfo();
        tools.isOpenAccount();
        //查询用户手机号
        tools.doGet(accountURL + tools.apiURL.queryUserInfo, {}, module.queryUserInfo);

        //推荐结果
        tools.doGet(accountURL +tools.apiURL.inviteList, {inviteAwardType:1}, module.inviteListRed);

    };
    //红包
    module.inviteListRed=function (data) {
        if(data.status==0){
            redPage=data.data.totalMoney;
            redList=data.data.members;
        }
        tools.doGet(accountURL +tools.apiURL.inviteList, {inviteAwardType:2}, module.inviteList);
    };
    //现金
    module.inviteList=function (data) {
        if(data.status==0){
            totalMoney=data.data.totalMoney;
            moneyList=data.data.members;
        }
        getData();

    };
    function  getData() {
        var obj={};
        var countP=0;
        for(var i=0;i<redList.length;i++){
            var key=redList[i].mobile;
            obj[key]=[];
            obj[key].gmtCreated=redList[i].gmtCreated;
            obj[key].isNew==redList[i].isNew;
            obj[key].redpage=redList[i].refereeReward;
            obj[key].money='';
            countP++;
        }



        setTimeout(function () {
            for(var n=0;n<moneyList.length;n++){
                var keys=moneyList[n].mobile;
                if(obj.hasOwnProperty(keys)){
                    obj[keys].money=moneyList[n].refereeReward;
                }else{
                    obj[keys]=[];
                    obj[keys].gmtCreated=moneyList[n].gmtCreated;
                    obj[keys].isNew=moneyList[n].isNew;
                    obj[keys].money=moneyList[n].refereeReward;
                    countP++;
                }
            }

            var info='';
            if(redPage==0&totalMoney!=0){
                info=totalMoney+'元现金';
            }else if(redPage!=0&totalMoney==0){
                info=redPage+'元红包';
            }else if(redPage==0&totalMoney==0){
                info='';
            }else{
                info=redPage+'元红包+'+totalMoney+'元现金';
            }
            if(countP!=0){
                $('#awardInfos').append('<tr><td><em >'+info+'</em></td> <td><em>'+countP+'</em>人</td></tr>');
            }
            var pro='';
            for(var key in obj){
                pro+='<tr><td>' +key+'</td> <td>'+obj[key].gmtCreated+'</td> <td>'+obj[key].redpage+'</td><td>'+obj[key].money+'</td><td>' + (obj[key].isNew == '1' ? '未投资' : '已投资') + '</td> </tr>'
            }
            $('#investList').append(pro);
        },20)
    }

    //查询用户手机号    复制分享
    module.queryUserInfo = function (data) {
        $('#biao1').text(accountURL+'register.html?referee='+data.data.mobile);
        $(document).ready(function () {
            $("#copy_btn").zclip({
                path: 'js/ZeroClipboard.swf',
                copy: accountURL+'register.html?referee=' + data.data.mobile,
                afterCopy: function () {
                    $("#biao1").css("background-color", '#cff');
                    $("<span id='msg'/>").insertAfter($('#copy_btn')).text('复制成功').fadeOut(400);
                    //alert("网址已经复制到您的剪贴板中\n您可以使用Ctrl+V快捷键粘贴到需要的地方")
                }
            });
        });
    };





    module.init();
})();